package com.jida.tijian.controller;

import com.jida.tijian.domain.Orders;
import com.jida.tijian.dto.OrderCheckRequest;
import com.jida.tijian.dto.ResponseObject;
import com.jida.tijian.exception.TijianAPPException;
import com.jida.tijian.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/*
订单模块的控制器
 */
@RestController
public class OrdersController {

    @Autowired
    OrdersService ordersService;

    /**
     * 保存订单数据
     */
    @RequestMapping("/saveOrders")
    public ResponseObject saveOrders(@RequestBody Orders orders) {
        System.out.println("医院编号：" + orders.getHpId());
        return ordersService.saveOrders(orders);
    }

    /**
     * 检查用户在指定日期是否已有预约
     */
    @PostMapping("/checkUserDateOrder")
    public ResponseObject checkUserDateOrder(@RequestBody OrderCheckRequest request) {
        try {
            return ordersService.checkUserDateOrder(request.getUserId(), request.getOrderDate());
        } catch (TijianAPPException e) {
            // 直接返回错误响应，而不是让异常传播
            return new ResponseObject(e.getCode(), e.getMessage());
        }
    }
}